import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;


public class XMLParser {
	
	
	public String createOutputFileNames(String inputFileName){
		String baseName= "";
		
		Pattern pattern = 	Pattern.compile("hsa[0-9]*") ;
		Matcher matcher =	pattern.matcher(inputFileName);
		while (matcher.find()) {
//		      System.out.print("Start index: " + matcher.start());
//		      System.out.print(" End index: " + matcher.end() + " ");
//		      System.out.println(matcher.group());
		      baseName = matcher.group();
		      break;
		    }
		return baseName;		
	}
	
	
	private void parseXmlFile(String filename){
		
//	Get the factory
		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		
		try{
//			Using the factory get the instance of document builder
			DocumentBuilder db = dbf.newDocumentBuilder();
			
			Document dom = db.parse(filename);
			
			String base = createOutputFileNames(filename);
			
			parseDocument(dom,base);
			
		}catch (ParserConfigurationException pce){
			pce.printStackTrace();
		} catch (SAXException se){
			se.printStackTrace();
		}catch (IOException ioe){
			ioe.printStackTrace();
		}
	}
	
	private void parseDocument(Document dom,String base){
//		get the root element
		Element docEle = dom.getDocumentElement();		
		
//		get a nodelist of entry elements
		
		
		List  entryList= getEntryElements(docEle);
		List  relationList= getRelationElements(docEle);
		List  reactionList= getReactionElements(docEle);
										
//		printDataEntryList(entryList);
//		printDataRelationList(relationList);
//		printDataReactionList(reactionList);
		
		writeEdgeNetworkData(relationList,base);
		writeReactionsNetworkData(reactionList,base);
		writeNodeAttributeData(entryList,base);
	}
	
	
	public void writeEdgeNetworkData(List relationList, String base){
	
		try{			
			
			
			FileWriter fw = new FileWriter("C:\\Users\\burcak\\workspace\\XMLParser\\"+ base +"_Network.txt");
			PrintWriter pw = new PrintWriter(fw);
	       
	        //Write to file for the first row
	        pw.print("Enrty1");
	        pw.print("\t");
//	        pw.print("Type");
//	        pw.print("\t");
	        pw.print("SubtypeName");
	        pw.print("\t");
//	        pw.print("SubtypeValue");
//	        pw.print("\t");
	        pw.println("Entry2");
	       
	        
	        Relation relation = null;
			Iterator it = relationList.iterator();
			
			while(it.hasNext()) {
							
				relation =	(Relation) it.next();			
				try{
					if(relation!=null){
						pw.print(relation.getEntry1());
				        pw.print("\t");
//				        pw.print(relation.getType());
//				        pw.print("\t");
				        
				        if (relation.getRelationSubtypeList()!=null){
							RelationSubtype relationSubtype;
							
							for(Iterator it1 = relation.getRelationSubtypeList().iterator(); it1.hasNext();){
								relationSubtype = (RelationSubtype)it1.next();
								
								pw.print(relationSubtype.getName());
						        pw.print("\t");
//						        pw.print( relationSubtype.getValue());
//						        pw.print("\t");
						        
						        break;
							}						
						}
				        
				        pw.println(relation.getEntry2());
				        				        
					}
				}
				catch(NullPointerException npe){
					npe.printStackTrace();
				}
			}
						
			
	        //Flush the output to the file
	        pw.flush();
	       
	        //Close the Print Writer
	        pw.close();
	       
	        //Close the File Writer
	        fw.close();        
		} catch (IOException ioe){
			ioe.printStackTrace();
		}
				
	}
	
	public void writeReactionsNetworkData(List reactionList, String base){
		try{
			int numberofReactions=0;
			
			FileWriter fw = new FileWriter("C:\\Users\\burcak\\workspace\\XMLParser\\" + base + "_Reactions.txt");
			PrintWriter pw = new PrintWriter(fw);
	       
	        //Write to file for the first row
	        pw.print("ReactionId");
	        pw.print("\t");
	        pw.print("ReactionName");
	        pw.print("\t");
	        pw.print("ReactionType");
	        pw.print("\t");
	        pw.print("SubstrateId");
	        pw.print("\t");
	        pw.print("SubstrateName");
	        pw.print("\t");
	        pw.print("--->");
	        pw.print("\t");
	        pw.print("ProductId");
	        pw.print("\t");
	        pw.print("ProductName");
	        pw.println("\t");
	        	       			
			Reaction reaction = null;
			Iterator it = reactionList.iterator();
			
			while(it.hasNext()) {			
				reaction =	(Reaction) it.next();			
				try{
					if(reaction!=null){
						numberofReactions++;
						
						pw.print(reaction.getId());
						pw.print("\t");	
						pw.print(reaction.getName());								
				        pw.print("\t");
				        pw.print(reaction.getType());								
				        pw.print("\t");
						
						if (reaction.getReactionSubstrateList()!=null){
							ReactionSubstrate reactionSubstrate;
							
							for(Iterator it1 = reaction.getReactionSubstrateList().iterator(); it1.hasNext();){
								reactionSubstrate = (ReactionSubstrate)it1.next();
								
								pw.print(reactionSubstrate.getId());
								pw.print("-");
								pw.print(reactionSubstrate.getName());								
						        pw.print("\t");								
							}						
						}

						pw.print("--->");
				        pw.print("\t");

						if (reaction.getReactionProductList()!=null){
							ReactionProduct reactionProduct;
							
							for(Iterator it2 = reaction.getReactionProductList().iterator(); it2.hasNext();){
								reactionProduct = (ReactionProduct)it2.next();
								
						        pw.print(reactionProduct.getId());
						        pw.print("-");
						        pw.print(reactionProduct.getName());							        
						        pw.println("\t");						        
							}						
						}
											
					}
				}
				catch(NullPointerException npe){
					npe.printStackTrace();
				}
			}
			
			System.out.print("Number of Reactions: ");
			System.out.println(numberofReactions);
			System.out.println("");
			
				
			
	        //Flush the output to the file
	        pw.flush();
	       
	        //Close the Print Writer
	        pw.close();
	       
	        //Close the File Writer
	        fw.close();        
		} catch (IOException ioe){
			ioe.printStackTrace();
		}
				

	}
	
	public void writeNodeAttributeData(List entryList, String base){		
		
		int numberofGenes=0;
		int numberofCompounds=0;
		int numberofOrthologs=0;
		int numberofMaps=0;
		int numberofGroups =0;
		int numberofEntries=0;
		String entryType;
		
		
		try{
			FileWriter fw = new FileWriter("C:\\Users\\burcak\\workspace\\XMLParser\\" + base + "_NodeAttributes.txt");
			PrintWriter pw = new PrintWriter(fw);
	       
	        //Write to file for the first row
	        pw.print("Enrty Id");
	        pw.print("\t");
	        pw.print("Entry Name");
	        pw.print("\t");
	        pw.print("Entry Type");
	        pw.print("\t");
	        pw.print("Entry Link");
	        pw.print("\t");
	        pw.print("Entry Reaction");	       
	       	pw.print("\t");
	        pw.print("Entry Component Id");	       	       
	        pw.print("\t");
	        pw.print("Entry Graphics Name");	       
	        pw.print("\t");
	        pw.print("Entry Graphics Type");	       
	        pw.print("\t");
	        pw.print("Entry Graphics X");	       
	        pw.print("\t");
	        pw.print("Entry Graphics Y");	       
	        pw.print("\t");
	        pw.print("Entry Graphics Width");	       
	        pw.print("\t");
	        pw.print("Entry Graphics Height");	       
	        pw.print("\t");
	        pw.print("Entry Graphics BgColor");	       
	        pw.print("\t");
	        pw.println("Entry Graphics FgColor");	       
	       
	        Entry entry = null;
			Iterator it = entryList.iterator();
			
			while(it.hasNext()) {			
				
				numberofEntries++;
				
				entry =	(Entry)it.next();			
				try{
					if(entry!=null){
						  	pw.print(entry.getId());
					        pw.print("\t");
					        pw.print(entry.getName());
					        pw.print("\t");					        
					        entryType = entry.getType();					        
					        pw.print(entryType);
					        pw.print("\t");
					        pw.print(entry.getLink());
					        pw.print("\t");
					        pw.print(entry.getReaction());	
					        pw.print("\t");
					        					        
					        if (entryType.equalsIgnoreCase("gene"))
					        	numberofGenes++;
					        else if (entryType.equalsIgnoreCase("map")) 
					        	numberofMaps++;
					        else if (entryType.equalsIgnoreCase("ortholog"))
					        	numberofOrthologs++;
					        else if (entryType.equalsIgnoreCase("compound"))
					        	numberofCompounds++; 
					        else if (entryType.equalsIgnoreCase("group"))
					        	numberofGroups++;
						
						if (entry.getEntryComponentList()!=null){
							EntryComponent entryComponent;
							
							for(Iterator it1 = entry.getEntryComponentList().iterator(); it1.hasNext();){
								entryComponent = (EntryComponent)it1.next();
								
								pw.print(entryComponent.getId());
								if (it1.hasNext())
									pw.print(",");
									
								
							}						
						}
						
						pw.print("\t");
						
						if (entry.getEntryGraphicsList()!=null){
							EntryGraphics entryGraphics;
							
							for(Iterator it2 = entry.getEntryGraphicsList().iterator(); it2.hasNext();){
								entryGraphics = (EntryGraphics)it2.next();
								
								pw.print(entryGraphics.getName());
								pw.print("\t");
								pw.print(entryGraphics.getType());
								pw.print("\t");
								pw.print(entryGraphics.getX());
								pw.print("\t");
								pw.print(entryGraphics.getY());
								pw.print("\t");
								pw.print(entryGraphics.getWidth());
								pw.print("\t");
								pw.print(entryGraphics.getHeight());
								pw.print("\t");
								pw.print(entryGraphics.getBgcolor());
								pw.print("\t");
								pw.print(entryGraphics.getFgcolor());
								pw.print("\t");								

							}											
						}
						pw.println();
					}
				}
				catch(NullPointerException npe){
					npe.printStackTrace();
				}
			}
	        

				System.out.print("Number of Entries: ");
				System.out.println(numberofEntries);
				System.out.println();
				
				System.out.print("Number of Genes: ");
				System.out.println(numberofGenes);
				
				System.out.print("Number of Maps: ");
				System.out.println(numberofMaps);
				
				System.out.print("Number of Orthologs: ");
				System.out.println(numberofOrthologs);
				
				System.out.print("Number of Compounds: ");
				System.out.println(numberofCompounds);
				
				System.out.print("Number of Groups: ");
				System.out.println(numberofGroups);
				
				int total =  numberofGenes + numberofMaps + numberofOrthologs + numberofCompounds + numberofGroups;
				
				System.out.printf("\nSum of (genes + maps + orthologs + compounds + groups) = %d \n", total);
				
				if (numberofEntries==total)
					System.out.println("Number of entries is equal to the sum");
				else 
					System.out.println("Number of entries is not equal to the sum");
					
					        
	        //Flush the output to the file
	        pw.flush();
	       
	        //Close the Print Writer
	        pw.close();
	       
	        //Close the File Writer
	        fw.close();        
		} catch (IOException ioe){
			ioe.printStackTrace();
		}

		
	}
	
	
	private List<Reaction>  getReactionElements(Element docEle){
		NodeList  reactionElements= docEle.getElementsByTagName("reaction");
		
		List<Reaction> reactionList = new ArrayList<Reaction>();
		
		if (reactionElements!=null && reactionElements.getLength()>0){
			for(int i =0; i<reactionElements.getLength();i++){
//				get the relation element
				Element reactionElement = (Element)reactionElements.item(i);
//				get the relation object
				Reaction reaction = getReaction(reactionElement);
//				Add it to the list
				reactionList.add(reaction);							
			}		
		}
		return reactionList;	
	}
	
	private List<Relation> getRelationElements(Element docEle){
		NodeList  relationElements= docEle.getElementsByTagName("relation");
		
		List<Relation> relationList = new ArrayList<Relation>();
		
		if (relationElements!=null && relationElements.getLength()>0){
			for(int i =0; i<relationElements.getLength();i++){
//				get the relation element
				Element relationElement = (Element)relationElements.item(i);
//				get the relation object
				Relation relation = getRelation(relationElement);
//				Add it to the list
				relationList.add(relation);							
			}		
		}
		return relationList;	
	}
		
	private List<Entry> getEntryElements(Element docEle){
		NodeList  entryElements= docEle.getElementsByTagName("entry");
		
		List<Entry> entryList = new ArrayList<Entry>();
		
		if (entryElements!=null && entryElements.getLength()>0){
			for(int i =0; i<entryElements.getLength();i++){
//				get the entry element
				Element entryElement = (Element)entryElements.item(i);
//				get the entry object
				Entry entry = getEntry(entryElement);
//				Add it to the list
				entryList.add(entry);							
			}		
		}
		return entryList;	
	}
	
//	@todo printData_reactinList
	private void printDataReactionList(List reactionList){

		System.out.println("No of reactions '" + reactionList.size() + "'.");

		Reaction reaction = null;
		Iterator it = reactionList.iterator();
		
		while(it.hasNext()) {			
			reaction =	(Reaction) it.next();			
			try{
				if(reaction!=null){
					System.out.println("<Reaction: "+ reaction.getId() +" "+ reaction.getName() +" "+ reaction.getType());
					
					if (reaction.getReactionSubstrateList()!=null){
						ReactionSubstrate reactionSubstrate;
						ReactionAlt reactionAlt;
						
						for(Iterator it1 = reaction.getReactionSubstrateList().iterator(); it1.hasNext();){
							reactionSubstrate = (ReactionSubstrate)it1.next();
							System.out.println(" <Substrate: " + reactionSubstrate.getId() +" " + reactionSubstrate.getName()+ "  </Substrate>");
							
							for(Iterator it1_1 = reactionSubstrate.getReactionSubstrateAltList().iterator(); it1_1.hasNext();){
								reactionAlt = (ReactionAlt) it1_1.next();
								System.out.println(" <Alt: " + reactionAlt.getName()+" </Alt>");								
							}
							
							
						}						
					}
					
					if (reaction.getReactionProductList()!=null){
						ReactionProduct reactionProduct;
						ReactionAlt reactionAlt;
						
						for(Iterator it2 = reaction.getReactionProductList().iterator(); it2.hasNext();){
							reactionProduct = (ReactionProduct)it2.next();
							System.out.println(" <Product: " + reactionProduct.getId() +" " + reactionProduct.getName()+ "  </Product>");
							
							for(Iterator it2_1= reactionProduct.getReactionProductAltList().iterator(); it2_1.hasNext();){
								reactionAlt = (ReactionAlt) it2_1.next();
								System.out.println(" <Alt: " + reactionAlt.getName()+" </Alt>");								
							}
						}						
					}
					
					System.out.println(" </Reaction>");
				}
			}
			catch(NullPointerException npe){
				npe.printStackTrace();
			}
		}
	}
	
	
	
	private void printDataRelationList(List relationList){

		System.out.println("No of relations '" + relationList.size() + "'.");

		Relation relation = null;
		Iterator it = relationList.iterator();
		
		while(it.hasNext()) {			
			relation =	(Relation) it.next();			
			try{
				if(relation!=null){
					System.out.println("<Relation: "+ relation.getEntry1() +" "+ relation.getType() +" "+ relation.getEntry2());
					
					if (relation.getRelationSubtypeList()!=null){
						RelationSubtype relationSubtype;
						
						for(Iterator it1 = relation.getRelationSubtypeList().iterator(); it1.hasNext();){
							relationSubtype = (RelationSubtype)it1.next();
							System.out.println(" <Subtype: " + relationSubtype.getName() +" " + relationSubtype.getValue()+ "  </Subtype>");						
						}						
					}
					
					System.out.println(" </Relation>");
				}
			}
			catch(NullPointerException npe){
				npe.printStackTrace();
			}
		}
	}
	
	private void printDataEntryList(List entryList){

		System.out.println("No of Entries '" + entryList.size() + "'.");

		Entry entry = null;
		Iterator it = entryList.iterator();
		
		while(it.hasNext()) {			
			entry =	(Entry)it.next();			
			try{
				if(entry!=null){
					System.out.println(" <Entry: "+ entry.getId()+" "+entry.getName()+" "+entry.getType()+ " "+ entry.getLink()+" "+ entry.getReaction());
					
					if (entry.getEntryComponentList()!=null){
						EntryComponent entryComponent;
						
						for(Iterator it1 = entry.getEntryComponentList().iterator(); it1.hasNext();){
							entryComponent = (EntryComponent)it1.next();
							System.out.println(" <Component: " + entryComponent.getId() + "  </Component>");						
						}						
					}
					
					if (entry.getEntryGraphicsList()!=null){
						EntryGraphics entryGraphics;
						
						for(Iterator it2 = entry.getEntryGraphicsList().iterator(); it2.hasNext();){
							entryGraphics = (EntryGraphics)it2.next();
							System.out.println(" <Graphics: "+entryGraphics.getName()+" "+entryGraphics.getType()+" "+entryGraphics.getX()
									+" "+entryGraphics.getY()+" "+entryGraphics.getWidth()+" "+entryGraphics.getHeight()+" "+entryGraphics.getBgcolor()+" "+entryGraphics.getFgcolor()+" </Graphics>");
						}											
					}
					
					System.out.println(" </Enrty>");
				}
			}
			catch(NullPointerException npe){
				npe.printStackTrace();
			}
		}
	}
	
	private Reaction getReaction(Element reactionElement){
		Reaction reaction = null;
		
		if(reactionElement!=null){ 
			int id = Integer.parseInt(reactionElement.getAttribute("id"));
			String name = reactionElement.getAttribute("name");
			String type = reactionElement.getAttribute("type");
			
			List reactionSubstrateList = getSubstrateList(reactionElement,"substrate");
			List reactionProductList = getProductList(reactionElement,"product");
			
			reaction = new Reaction(id,name,type,reactionSubstrateList, reactionProductList);
		}								
		return reaction;	
	}	
	
	private List getSubstrateList(Element  ele, String tagName){
		List reactionSubstrateList = new ArrayList();
		ReactionSubstrate reactionSubstrate = null;
		
		NodeList nl = ele.getElementsByTagName(tagName);
		if(nl != null && nl.getLength() > 0) {
			
			for (int i= 0;i<nl.getLength();i++){
				Element el = (Element)nl.item(i);
				if (el!=null){
					int id = Integer.parseInt(el.getAttribute("id"));						
					String name = el.getAttribute("name");
					
					List reactionSubstrateAltList = getAltList(el,"alt");
					
					reactionSubstrate = new ReactionSubstrate(id, name, reactionSubstrateAltList);
					reactionSubstrateList.add(reactionSubstrate);				
				}						
			}
		}		
		return reactionSubstrateList;
	}
	
	
	private List getProductList(Element  ele, String tagName){
		List reactionProductList = new ArrayList();
		ReactionProduct reactionProduct = null;
		
		NodeList nl = ele.getElementsByTagName(tagName);
		if(nl != null && nl.getLength() > 0) {
			
			for (int i= 0;i<nl.getLength();i++){
				Element el = (Element)nl.item(i);
				if (el!=null){
					int id = Integer.parseInt(el.getAttribute("id"));						
					String name = el.getAttribute("name");
					
					List reactionProductAltList = getAltList(el,"alt");
					
					reactionProduct = new ReactionProduct(id, name, reactionProductAltList);
					reactionProductList.add(reactionProduct);				
				}						
			}
		}		
		return reactionProductList;
	}
	
	private List getAltList(Element ele, String tagName){
		List reactionAltList = new ArrayList();
		ReactionAlt reactionAlt = null;
		
		NodeList nl = ele.getElementsByTagName(tagName);
		if(nl != null && nl.getLength() > 0) {
			
			for (int i= 0;i<nl.getLength();i++){
				Element el = (Element)nl.item(i);
				if (el!=null){
					String name = el.getAttribute("name");
										
					reactionAlt = new ReactionAlt(name);
					reactionAltList.add(reactionAlt);				
				}						
			}
		}		
		return reactionAltList;
	
	}
	
	
	private Relation getRelation(Element relationElement){
		Relation relation = null;
		
		if(relationElement!=null){ 
			int entry1 = Integer.parseInt(relationElement.getAttribute("entry1"));
			int entry2 = Integer.parseInt(relationElement.getAttribute("entry2"));
			String type = relationElement.getAttribute("type");
			
			List relationSubtypeList = getSubtypeList(relationElement,"subtype");
			
			relation = new Relation(type, entry1, entry2, relationSubtypeList);
		}								
		return relation;	
	}	
	
	
	private List getSubtypeList(Element  ele, String tagName){
		List relationSubtypeList = new ArrayList();
		RelationSubtype relationSubtype = null;
		
		NodeList nl = ele.getElementsByTagName(tagName);
		if(nl != null && nl.getLength() > 0) {
			
			for (int i= 0;i<nl.getLength();i++){
				Element el = (Element)nl.item(i);
				if (el!=null){
					String name = el.getAttribute("name");						
					String value = el.getAttribute("value");
					
					relationSubtype = new RelationSubtype(name,value);
					relationSubtypeList.add(relationSubtype);				
				}						
			}
		}		
		return relationSubtypeList;
	}
	
	/**
	 * I take an entry element and read the values in, create
	 * an Entry object and return it
	 */
	private Entry getEntry(Element entryElement){
		//for each <entry> element get text or int values of
				//id, name, type, link,  reaction, component, graphics
		Entry entry = null;
		
		if(entryElement!=null){ 
			int id = Integer.parseInt(entryElement.getAttribute("id"));
			String name = entryElement.getAttribute("name");
			String type = entryElement.getAttribute("type");
			String link = entryElement.getAttribute("link");
			String reaction = entryElement.getAttribute("reaction");			
			List entryComponentList = getComponentList(entryElement,"component");
			List entryGraphicsList = getGraphicsList(entryElement,"graphics");
			
			entry = new Entry(id,name,type,link,reaction,entryComponentList,entryGraphicsList);
		}								
		return entry;		
	}
	

	private List getComponentList(Element  ele, String tagName){
		List entryComponentList = new ArrayList();
		EntryComponent entryComponent = null;
		
		NodeList nl = ele.getElementsByTagName(tagName);
		if(nl != null && nl.getLength() > 0) {
			
			for (int i= 0;i<nl.getLength();i++){
				Element el = (Element)nl.item(i);
				if (el!=null){
					int id = Integer.parseInt(el.getAttribute("id"));					
					entryComponent =new EntryComponent(id);
					entryComponentList.add(entryComponent);				
				}						
			}
		}		
		return entryComponentList;
	}
	
	private List getGraphicsList(Element  ele, String tagName){
		List entryGraphicsList = new ArrayList();
		EntryGraphics entryGraphics = null;
		
		NodeList nl = ele.getElementsByTagName(tagName);
		if(nl != null && nl.getLength() > 0) {
			for (int i= 0;i<nl.getLength();i++){
				Element el = (Element)nl.item(i);
				if (el!=null){
					String name = el.getAttribute("name");
					String type = el.getAttribute("type");
					int x = Integer.parseInt(el.getAttribute("x"));
					int y = Integer.parseInt(el.getAttribute("y"));
					int width = Integer.parseInt(el.getAttribute("width"));
					int height = Integer.parseInt(el.getAttribute("height"));
					String fgcolor = el.getAttribute("fgcolor");
					String bgcolor = el.getAttribute("bgcolor");
									
					entryGraphics =new EntryGraphics(name,type,x,y,width,height,bgcolor,fgcolor);
					entryGraphicsList.add(entryGraphics);
				}			
			}
		}		
		return entryGraphicsList;
	}
	
	/**
	 * Calls getIntValue and returns a int value
	 */
	private int getIntValue(Element ele, String tagName) {
		int intVar = 0;
		try{
			intVar = Integer.parseInt(getTextValue(ele,tagName));
		}catch(NumberFormatException nfe){
			nfe.printStackTrace();
		}
		return intVar;
	}	
	
	/**
	 * I take a xml element and the tag name, look for the tag and get
	 * the text content
	 * i.e for <employee><name>John</name></employee> xml snippet if
	 * the Element points to employee node and tagName is 'name' I will return John
	 */
	private String getTextValue(Element ele, String tagName) {
		String textVal = null;
		NodeList nl = ele.getElementsByTagName(tagName);
		if(nl != null && nl.getLength() > 0) {
			Element el = (Element)nl.item(0);
			textVal = el.getFirstChild().getNodeValue();
		}

		return textVal;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println("XML Parser Using Document  Object Model");
//		System.out.println(new File(".").getAbsolutePath());
		XMLParser xmlParser = new XMLParser();
		xmlParser.parseXmlFile(args[0]);

	}

}
